package com.kbbywyclient.presenter;

import android.content.Context;
import com.kbbywyclient.data.model.LoanIndexModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.MainContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Observer;

/**
 * Created by FHW
 * on 2017/3/21
 */

public class MainPresenter extends BasePresenter implements MainContract.Presenter {
    private MainContract.View view;
    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil rsaJsonUtil;

    //为注解了@Inject的对象注入无参构造方法构造的对象
    @Inject
    public MainPresenter(MainContract.View view) {
        this.view = view;

    }


    @Override
    public void getLoanIndex(String salesID) {
        rsaJsonUtil.put("SalesID", salesID);
        ApiServiceHelper.
                appointThreadNormal(apiService.getLoanIndex(rsaJsonUtil.getRsaParams())).
                subscribe(new Observer<LoanIndexModel>() {
                    @Override
                    public void onCompleted() {
                        view.finishRefresh();
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.finishRefresh();
                        HttpExcUtil.printError(e);
                    }

                    @Override
                    public void onNext(LoanIndexModel loanIndexModel) {
                        view.loadSucLoanIndex(loanIndexModel.getData());
                    }
                });

    }

//    @Override
//    public void getCreditCardIndex(String saleID) {
//        rsaJsonUtil.put("SalesID", saleID);
//        apiService.getCreditCardIndex(rsaJsonUtil.getRsaParams())
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<CreditCardIndexModel>() {
//                    @Override
//                    public void onCompleted() {
//                        view.finishRefresh();
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        view.finishRefresh();
//                        HttpExcUtil.printError(e);
//                    }
//
//                    @Override
//                    public void onNext(CreditCardIndexModel creditCardIndexModel) {
//                        view.loadSucCreditIndex(creditCardIndexModel.getData());
//                    }
//                });
//    }

//    @Override
//    public void getSalesSetting(String SalesID) {
//        rsaJsonUtil.put("SalesID", SalesID);
//        view.showLoadingDialog(mContext.getString(R.string.text_loading));
//        apiService.getSalesSetting(rsaJsonUtil.getRsaParams())
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<SalesSettingModel>() {
//                    @Override
//                    public void onCompleted() {
//                        view.closeLoadingDialog();
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        view.closeLoadingDialog();
//                        HttpExcUtil.printError(e);
//                    }
//
//                    @Override
//                    public void onNext(SalesSettingModel salesSettingModel) {
//                        view.loadSucSaleSetting(salesSettingModel.getData());
//                    }
//                });
//    }

}
